<template>
  <div id="app" class="SkTemperature">
    <class-and-table
      :tableName="'体温数据'"
      :data="data"
      :rowKey="rowKey"
      :threshold="threshold"
      :columns="columns"
      v-on="$listeners"
      @classData="getClassData"
    >
      <template slot="tableHeader">
        <a-row type="flex" :gutter="[14, 38]">
          <a-col v-for="item in temperatureList" :key="item.num">
            <a-card
              class="card-shadow"
              style="width:130px;border-radius: 6px;"
              :bodyStyle="{
                padding: '5px 15px'
              }"
            >
              <a-row type="flex" justify="space-between">
                <a-col>
                  <span>{{ item.title }}</span>
                </a-col>
                <a-col>
                  <span>{{ item.val }}人</span>
                </a-col>
              </a-row>
            </a-card>
          </a-col>
        </a-row>
      </template>
      <template slot="detailBtn">
        <a-button size="small" type="primary" @click="viewDetail">
          <span>查看详情</span>
          <a-icon type="caret-right" />
        </a-button>
      </template>
    </class-and-table>
  </div>
</template>
<script>
import classAndTable from "@/components/skComponent/classAndTable.vue";
import { getAction } from "@/api/manage.js";
import { filterDictTextByCache } from '@/components/dict/JDictSelectUtil'
export default {
  name: 'SkTemperature',
  data() {
    return {
      temperatureList: [],
      data: [],
      threshold: 37,
      columns:[],
      rowKey:"",
      columns1: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 70,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '测量时间',
          align: 'center',
          dataIndex: 'examinationTime'
        },
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'studentName'
        },
        {
          title: '性别',
          align: 'center',
          dataIndex: 'sex',
          customRender:function(text){
            return filterDictTextByCache("sex",text)
          }
        },
        {
          title: '体温',
          align: 'center',
          dataIndex: 'temperature',
          scopedSlots: { customRender: 'temperature' }
        },
        {
          title: '家长电话',
          align: 'center',
          dataIndex: 'guardianPhone'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'isNormal',
          scopedSlots: { customRender: 'isNormal' }
        },
        
      ],
      columns2:[
        {
          title: '年级',
          align: 'center',
          dataIndex: 'classType'
        },
        {
          title: '班级',
          align: 'center',
          dataIndex: 'className'
        },
        {
          title: '班级人数',
          align: 'center',
          dataIndex: 'shouldNum'
        },
        {
          title: '测温人数',
          align: 'center',
          dataIndex: 'actualNum'
        },
        {
          title: '未测温人数',
          align: 'center',
          dataIndex: 'noTemperatureNum'
        },
        {
          title: '异常人数',
          align: 'center',
          dataIndex: 'abnormalNum'
        },
      ],
      classId:""
    }
  },
  components: {
    classAndTable
  },

  filters: {},

  computed: {
    
  },

  created() {
    this.getTemperature();
  },

  activated() {},

  mounted() {},

  methods: {
    getClassData(data){
      this.classId = data.classId;
      this.data = [];
      if (this.classId) {
        this.getClassTemperature();
      }else{
        this.classId = "0"
        this.getTemperature()
      }
    },
    viewDetail(){
      this.$emit("detailData",false)
    },
    // 查询班级体温
    getClassTemperature(){
      this.columns = this.columns1;
      this.rowKey = "studentId";
      let url = "/health/skTemperatureRecord/getTemperatureStatistical";
      const params = {
        classId:this.classId?this.classId: null,
        startDate:this.$skCommon.getDate(0),
        endDate:this.$skCommon.getDate(0),
      }
      getAction(url,params).then((res)=>{
        if(res.success){
          this.data = res.result;
        } else {
          this.$message.warning(res.message);
        }
      }).catch((error)=>{
        console.error(error);
      })
    },
    // 查询全园体温人数
    getTemperature(){
      this.rowKey = "classId";
      this.columns = this.columns2;
      let url = "/health/skTemperatureRecord/getTotalTemperatureStatistical";
      const params = {
        // classId:this.classId?this.classId: null,
        startDate:this.$skCommon.getDate(0),
        endDate:this.$skCommon.getDate(0),
        // startDate:"2023-03-18",
        // endDate:"2023-03-19",
        byType:"day",
        statisticalScope:"class"
      }
      getAction(url,params).then((res)=>{
        if(res.success){
          let abnormalNumTotal = 0;
          let noTemperatureNumTotal = 0;
          let actualNumTotal = 0;
          let shouldNumTotal = 0;

          res.result.forEach(item => {
            abnormalNumTotal += item.abnormalNum || 0
            noTemperatureNumTotal += item.noTemperatureNum || 0
            actualNumTotal += item.actualNum || 0
            shouldNumTotal += item.shouldNum || 0
          });
          this.temperatureList = [
            {title:"异常",val:abnormalNumTotal},
            {title:"未测",val:noTemperatureNumTotal},
            {title:"实测",val:actualNumTotal},
            {title:"应测",val:shouldNumTotal},
          ]
          this.data = res.result;
        } else {
          this.$message.warning(res.message);
        }
      }).catch((error)=>{
        console.error(error);
      })
    }
  }
}
</script>
<style scoped>
/* @import url(); 引入css类 */
</style>
